<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>盘点录入-WMS库存管理系统</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">

    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="sp-wrapper">
        <h2 class="sp-title"><span>盘点出库录入</span></h2>
        <form action="/stocktaking/counted" method="post" id="sp-form">
            <div class="sp-tool">
			<span class="fl">
                <input type="hidden" name="invoiceId"  th:value="${invoiceId}">
                <b>单据编号：[[${billNo}]]</b>
            </span>
                <span class="fr">
                   <!-- <i class="save" id="save" th:if="${status == T(com.b2c.entity.erp.enums.ErpStocktakingInvoiceStatusEnum).WaitCounted.index}">提交盘点数据</i>-->
                    <i th:if="${status == T(com.b2c.entity.erp.enums.ErpStocktakingInvoiceStatusEnum).WaitCountedConfirm.index}" id="counted_confirm" th:attr="data-id=${invoiceId}">盘点确认</i>

                </span>
            </div>
            <div class="sp-table">
                <table>
                    <thead>
                    <tr>
                        <th>SKU</th>
                        <th>规格</th>
                        <th>仓位</th>
                        <th>当前库存</th>
                        <th>盘点库存</th>
                    </tr>
                    </thead>
                    <tbody id="sp-data">
                    <tr th:each="item:${list}">
                        <td>
                            <input type="hidden" name="itemId"  th:value="${item.id}">
                            <input type="hidden" name="currentQty"  th:value="${item.currentQty}">
<!--                            <input type="hidden" name="specNumber" class="specNumber" th:value="${item.goods_spec_number}">-->
<!--                            <input type="hidden" name="specId" class="specId" th:value="${item.goods_spec_id}">-->
<!--                            <input type="hidden" name="goodsId" class="goodsId" th:value="${item.goods_id}">-->
<!--                            <input type="hidden" name="goodsNumber" class="goodsNumber" th:value="${item.goods_number}">-->
<!--                            <input type="hidden" name="locationId" class="locationId" th:value="${item.locationId}">-->
                            <b th:text="${item.goods_spec_number}"></b>
                        </td>
                        <td>
                            <b th:text="${item.colorValue}"></b>
                            <b th:text="${item.sizeValue}"></b>
                        </td>
                        <td>
                            <b th:text="${item.locationName}"></b>
                        </td>
                        <td>
                            <b th:text="${item.currentQty}"></b>
                        </td>
                        <td>
                            <input  type="number" name="counted"  th:value="${item.countedQty}">
                        </td>
                    </tr>

                    </tbody>
                </table>
            </div>

        </form>
    </div>

    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script>
        $(function () {

        // 保存
        $('#save').click(function () {

            //检查商品规格
            var returnResult = true;
            //检查是否填写盘点数量
            $("input[name^='counted']").each(function (i, el) {
                if ($(this).val() == "" || $(this).val() < 0 ) {
                    returnResult = false;
                }
            });
            if (returnResult == false) {
                alert("请输入正确的盘点数量")
                return false;
            }

            $('#sp-form').submit();
        });
        });
    </script>
    <!-- end sp-wrapper -->
    <script type="text/javascript">
        $(function () {
            // 盘点确认
            $('#counted_confirm').click(function () {
                var obj = $(this).parent().parent();
                var id = $(this).attr('data-id');
                if(confirm("盘点确认之后库存数据将会改变，确定要操作吗？")){
                    //alert(id);
                    // ajax处理
                    $.ajax({
                        url: "/stocktaking/counted_confirm",
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json",
                        data: JSON.stringify({invoiceId: id}),
                        success: function (res) {
                            if (res.code == 0) {
                                Tips.alert('确认成功', function () {
                                    location.reload(true);
                                });

                            }else  Tips.alert(JSON.stringify(res));
                        }
                    });
                }
            });


        });
    </script>
    <script>
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#form_date' //指定元素
            });
        });
    </script>
</div>
</body>
<html>
